package stream;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @PackageName: stream
 * @ClassName:
 * @author: wxc
 * @date 2021/5/14 demo01
 */
public class demo01 {
    public static void main(String[] args) {
        System.out.println("开始");
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                list.add("222" + i);
            }
            list.add("小组");
        }
        printList(list);
        System.out.println();
        System.out.println("---------筛选集合中内容------------");
        //进行集合过滤操作
        List<String> list1 = new ArrayList<>();
        list1.add("2220");
        list1.add("2222");
        list1.add("2224");
        List<String> collect = list.stream().filter(s -> s.equals("2220") || s.equals("2222")).collect(Collectors.toList());
        printList(collect);
        System.out.println();
        System.out.println("----------关联其他集合筛选-----------");
        List<String> collect1 = list.stream().filter(s -> list1.contains(s)).collect(Collectors.toList());
        printList(collect1);

    }

    private static void printList(List<String> list) {
        if (list != null) {
            list.forEach(s -> {
                System.out.print(s+" ");
            });
        }
    }
}
